package service

import (
	"context"
	"errors"
	__ "order_srv/basic/orderproto"
	"order_srv/handler/dao"
)

// 订单取消删除
func (s *Server) OrderCancellationDel(_ context.Context, in *__.OrderCancellationDelReq) (*__.OrderCancellationDelResp, error) {
	if in.Id <= 0 {
		return nil, errors.New("id参数错误")
	}

	_, err := dao.OrderCancellationDel(in)
	if err != nil {
		return nil, errors.New(err.Error())
	}

	return &__.OrderCancellationDelResp{}, nil
}

// 订单取消详情
func (s *Server) OrderCancellationDetail(_ context.Context, in *__.OrderCancellationDetailReq) (*__.OrderCancellationDetailResp, error) {
	if in.Id <= 0 {
		return nil, errors.New("id参数错误")
	}
	detail, err := dao.OrderCancellationDetail(in)
	if err != nil {
		return nil, errors.New(err.Error())
	}
	return &__.OrderCancellationDetailResp{
		Id:              detail.Id,
		OrderId:         detail.OrderId,
		Reason:          detail.Reason,
		Liability:       uint64(detail.Liability),
		CancellationFee: float32(detail.CancellationFee),
		UserId:          detail.UserId,
		Identity:        int32(detail.Identity),
	}, nil
}

// 订单取消列表
func (s *Server) OrderCancellationList(_ context.Context, in *__.OrderCancellationListReq) (*__.OrderCancellationListResp, error) {
	list, err := dao.OrderCancellationList(in)
	if err != nil {
		return nil, errors.New(err.Error())
	}

	return &__.OrderCancellationListResp{
		List: list,
	}, nil
}
